package org.javabasics.stream;

import com.sun.org.apache.xpath.internal.SourceTree;

import java.util.function.Supplier;
import java.util.stream.Stream;

/**
 * Created by LUOLIANG on 2016/10/25.
 * 用stream表示自然数集合
 */
public class NaturalSupplier implements Supplier<Long> {
    long value = 0;

    @Override
    public Long get() {
        this.value++;

        return this.value;
    }

    public static void main(String[] args) {
        Stream<Long> natural = Stream.generate(new NaturalSupplier());
        natural.map((x) -> {
            return x * x;
        }).limit(10).forEach(System.out::println);
    }
}


